<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Buyer Quotation</title>
		<link rel="stylesheet" href="../../css/styles.css" type="text/css" />
		<script type="text/javascript" src="js/validation.js"></script>
	</head>
	<script type="text/javascript">
	  
	  function showEnterForm(){
	      document.getElementById("enterDiv").style.display = "block";
	      document.getElementById("viewDiv").style.display = "none";
	  }
	  
	  function showSearchForm(){
	      document.getElementById("enterDiv").style.display = "none";
	      document.getElementById("viewDiv").style.display = "block";
	  }
	  
	  function setDisplay(){
	     var getDetailsField = document.getElementById("getDetailsField");
	     var saveDetailsField = document.getElementById("saveDetailsField");
	     if(getDetailsField != null){
	        showSearchForm();
	     }else if(saveDetailsField != null){
	       showEnterForm();
	     }
	  }
	   function validateFormOnSubmit(theForm) {
		var reason = "";
		
		reason += validateEmpty(theForm.strBuyQuoteNumber);
		reason += validateEmpty(theForm.buyerId);
		reason += validateEmpty(theForm.strItemName);
	  	reason += validateEmpty(theForm.numItemQuantity);
	  	reason += validateEmpty(theForm.strItemRate);
	  	reason += validateEmpty(theForm.strAmount);
	  	reason += validateEmpty(theForm.numInvoiceNo);
		if (reason != "") {
	    alert("Some fields need correction:\n" + reason);
	    return false;
	  }
	 return true;
	}
	function validateFormOnSearch(theForm){
		var reason = "";
		
		reason +=validateSelectProduct(theForm.bitemSearch);
		if (reason !=""){
		alert("Error Message:\n" + reason);
		return false;
		}
		return true;
	}
	</script>
<body onLoad="javascript:setDisplay();">
	<div id="container">
		<jsp:include page="/jsp/menu.jsp" />
                <div style="height:420px;">
			  		<div class="path">
						<br><a href="home.htm"> Home </a>-&gt;
						<a> Account </a>-&gt;
						<a> Sale </a>-&gt;
						<a href="buyerQuotation.htm"> Quotation Details </a>
			  		</div>
			  		<div id="leftDiv" style="margin-left: 10px;margin-top: 20px">
			   			<b>Buyer Details</b><br><br>
						<fieldset style="height:80px; width:200px;background: #FFF;">
						<table cellpadding=20>
						<tr>
							<td>
								<a href="javascript:showSearchForm()">
			                        	View Quotation Details
								</a>
							</td>
						</tr>
						<tr>
							<td>
			                 	<a href="javascript:showEnterForm()">
			                        	Enter Quotation Details
			                 	</a>
							</td>
						</tr>
						</table>
						</fieldset>
			  		</div>
				</div>
				<form:form method="POST" action="getBuyerQuotationDetails.htm" commandName="buyerQuotationDetails" onsubmit="return validateFormOnSearch(this)">
                 <div id="viewDiv" class="maininfo" style="display: none">
                 	<div class="lable">
						Quotation Details
					</div>
						<div id="searchForm">
					   <table>
								<tr>
									<td>Enter Product Name <span class="mand-star">*</span></td>
									<td><form:select path="bitemSearch">
										<form:option value="" label="------Select------"></form:option>
										<c:forEach items="${model.bItemList}" var="buyerQuotation">
											<form:option value="${buyerQuotation.strItemName}">${buyerQuotation.strItemName}</form:option>
										</c:forEach>
									</form:select></td>
								</tr>
								<tr>
									<td></td>
									<td><input type="submit" value="Search" size=5></td>
								<tr>
							</table>
					</div>
						<c:if test="${!empty model.buyerQuotList}">
						<div id="viewTable">
							<table cellpadding="10">
								<tr>
									<th> BuyerQuot ID </th>
									<th> BuyerQuot No </th>
									<th> Buyer Name </th>
									<th> Item Quantity </th>
									<th> Item Rate </th>
									<th> Item Amount </th>
									<th> Invoice No </th>
								</tr>
							<c:forEach items="${model.buyerQuotList}" var="buyerQuotList">
								<tr>
									<td><c:out value="${buyerQuotList.numBuyQuotId}"></c:out></td>
									<td><c:out value="${buyerQuotList.strBuyQuoteNumber}"></c:out></td>
									<td><c:out value="${buyerQuotList.objBuyer.numBuyerId}"></c:out></td>
									<td><c:out value="${buyerQuotList.numItemQuantity}"></c:out></td>
									<td><c:out value="${buyerQuotList.strItemRate}"></c:out></td>
									<td><c:out value="${buyerQuotList.strAmount}"></c:out></td>
									<td><c:out value="${buyerQuotList.numInvoiceNo}"></c:out></td>
								</tr>
							</c:forEach> 	
							</table>
						</div>
						</c:if>

				  </div>
				 </form:form>
			<form:form method="POST" action="saveBuyerQuotationDetails.htm" commandName="buyerQuotationDetails" onsubmit=" return validateFormOnSubmit(this)">
			 		<div id="enterDiv" class="maininfo" style="display: none">
			 			<div class="lable">
							Enter Quotation Details
							<c:if test="${model.isSave}">
								<div id="result"> <c:out value="Submitted Successfully"></c:out></div>
							</c:if>
						</div>
						<table>
								<tr>
									<th> Buyer Quotation No. <span class="mand-star">*</span></th>
									<td><form:input path="strBuyQuoteNumber" /></td>
								</tr>
								<tr>
									<th> Buyer Id <span class="mand-star">*</span></th>
									<td><form:input path="buyerId" /></td>
								</tr>
								<tr>	
									<th> Item Name<span class="mand-star">*</span> </th>
									<td><form:input path="strItemName" /></td>
								</tr>
								<tr>
									<th> Quantity <span class="mand-star">*</span> </th>
									<td><form:input path="numItemQuantity" /></td>
								</tr>
								<tr>
									<th> Rate <span class="mand-star">*</span> </th>
									<td><form:input path="strItemRate" /></td>
								</tr>
								<tr>
									<th>Amount  </th>
									<td><form:input path="strAmount" /></td>
								</tr>
								<tr>
									<th>Invoice No. <span class="mand-star">*</span> </th>
									<td><form:input path="numInvoiceNo" /></td>
								</tr>
								<tr>	
									<th></th>
									<td><input type="submit" name="submit"  value="Submit"></td>
								</tr>
							</table>
					</div>
				</form:form>
			
			<c:if test="${model.isGet}">
			   <input id="getDetailsField" type="hidden" name="getDetailsField"/>  
			</c:if>
			<c:if test="${model.isSave}">
			   <input id="saveDetailsField" type="hidden" name="saveDetailsField"/>  
			</c:if>		
			<div id="footer">
				<jsp:include page="/jsp/footer.jsp" />
			</div>
	</div>
</body>
</html>